<script setup lang="ts">
import {House, Plus, UserFilled} from "@element-plus/icons-vue";
import router from "@/router";
</script>

<template>
  <div class="common-layout">
    <el-container>
      <el-header>
        <div class="header-content">
          <img src="@/assets/bi.svg" alt="Logo" class="logo">
          <h1 class="title">鱼智能BI</h1>
        </div>
      </el-header>
      <el-container>
        <el-aside width="220px">
          <el-menu class="side-menu" :default-active="router.currentRoute.value.path" router>
            <el-menu-item index="/main" @click="router.push('/main')" class="menu-item">
              <el-icon><House /></el-icon>
              <span class="menu-text">首页</span>
            </el-menu-item>
            <el-menu-item index="/addChart" @click="router.push('/addChart')" class="menu-item">
              <el-icon><Plus /></el-icon>
              <span class="menu-text">添加图表</span>
            </el-menu-item>
            <el-menu-item index="/mychart" @click="router.push('/mychart')" class="menu-item">
              <el-icon><UserFilled /></el-icon>
              <span class="menu-text">我的图表</span>
            </el-menu-item>
          </el-menu>
        </el-aside>
        <el-container>
          <el-main>
            <div class="card-container">
              <router-view></router-view>
            </div>
          </el-main>
          <el-footer>
            <div class="footer-content">
              <a href="https://gitee.com/wangfenghuan3399/smart-bi-back" class="footer-link">
                鱼智能BI开源项目
              </a>
              <img src="@/assets/github.svg" alt="GitHub" class="github-icon">
            </div>
          </el-footer>
        </el-container>
      </el-container>
    </el-container>
  </div>
</template>

<style scoped lang="less">
// 设计变量
@primary-color: #409EFF;
@accent-color: #6C5CE7;
@text-primary: #2D3436;
@background-light: #F8F9FA;
@border-radius: 12px;
@transition-duration: 0.25s;

.common-layout {
  height: 100vh;
  max-width: 1440px;
  margin: 0 auto;
  background: @background-light;
}

.el-header {
  background: white;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  padding: 0 40px;

  .header-content {
    height: 100%;
    display: flex;
    align-items: center;
    gap: 16px;

    .logo {
      width: 48px;
      height: 48px;
      transition: transform @transition-duration ease;

      &:hover {
        transform: rotate(15deg);
      }
    }

    .title {
      margin: 0;
      font-size: 24px;
      font-weight: 600;
      color: @text-primary;
      position: relative;
      padding-bottom: 8px;

      &::after {
        content: '';
        position: absolute;
        bottom: 0;
        left: 0;
        width: 40px;
        height: 3px;
        background: @primary-color;
        border-radius: 2px;
        transition: width @transition-duration ease;
      }

      &:hover::after {
        width: 60px;
      }
    }
  }
}

.side-menu {
  border-right: none;
  background: linear-gradient(145deg, #ffffff, #f8f9fa);
  box-shadow: 4px 0 12px rgba(0, 0, 0, 0.05);

  .menu-item {
    margin: 8px 12px;
    border-radius: 8px;
    transition: all @transition-duration cubic-bezier(0.4, 0, 0.2, 1);

    &:hover {
      background: @primary-color !important;
      transform: translateX(8px);

      .el-icon, .menu-text {
        color: white !important;
      }
    }

    &.is-active {
      background: fade(@accent-color, 10%);
      border-right: 3px solid @accent-color;
    }

    .el-icon {
      font-size: 20px;
      margin-right: 12px;
    }

    .menu-text {
      font-size: 15px;
      font-weight: 500;
    }
  }
}

.card-container {
  background: white;
  border-radius: @border-radius;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.06);
  min-height: calc(100vh - 180px);
  padding: 24px;
  transition: box-shadow @transition-duration ease;

  &:hover {
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
  }
}

.footer-content {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 24px;
  padding: 16px 0;
  border-top: 1px solid rgba(0, 0, 0, 0.05);

  .footer-link {
    color: fade(@text-primary, 80%);
    text-decoration: none;
    font-size: 14px;
    transition: all @transition-duration ease;

    &:hover {
      color: @primary-color;
      transform: translateY(-1px);
    }
  }

  .github-icon {
    width: 24px;
    height: 24px;
    opacity: 0.7;
    transition: all @transition-duration ease;

    &:hover {
      opacity: 1;
      transform: scale(1.1) rotate(5deg);
    }
  }
}

@media (max-width: 768px) {
  .el-header {
    padding: 0 16px;

    .title {
      font-size: 20px;

      &::after {
        width: 30px;
      }

      &:hover::after {
        width: 40px;
      }
    }
  }

  .el-aside {
    width: 160px !important;
  }

  .card-container {
    padding: 16px;
    margin: 0 8px;
  }

  .footer-content {
    flex-direction: column;
    gap: 12px;
    text-align: center;
  }
}

@media (max-width: 480px) {
  .side-menu {
    .menu-text {
      display: none;
    }

    .el-icon {
      margin-right: 0 !important;
    }
  }
}
</style>
